package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type AppConfig struct {
	MySQLConfig
	RedisConfig
	ALiPayConfig
}
type MySQLConfig struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
}
type ALiPayConfig struct {
	APPID      string
	PrivateKey string
	NotifyURL  string
	ReturnURL  string
}
type RedisConfig struct {
	Addr     string
	Password string
	Db       int
}

var AppConf AppConfig

func ConfigInit() {
	viper.SetConfigFile("../api/appconfig/dev.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		fmt.Println("配置读取信息失败", err)
		return
	}
	fmt.Println("配置读取信息成功")
	err = viper.Unmarshal(&AppConf)
	if err != nil {
		fmt.Println("配置解析信息失败", err)
		return
	}
	fmt.Println(AppConf)
	fmt.Println("配置解析信息成功")
}
